/*************
author:: libo
license:: MIT
*****************/
#ifndef _LIBCELL_TOOLS_IO_H
#define _LIBCELL_TOOLS_IO_H
#include<Mesh_IO/Mesh_IO.h>
#include "libcell_tools_formats.h"
#define quote lib_cell_quote
#define _ReadOff_   LibCell_ReadOff_
#define _ReadCell_  LibCell_ReadCell_
#define _WriteCell_ LibCell_WriteCell_
#define _ReadArray_ LibCell_ReadArray_

#ifdef __cplusplus
extern "C" {
#endif
static void _Read_(Mesh*mesh,char const * filename)
{
    int i=0;
    while(filename[i]!='\0')
    {
        i++;
    }
    i--;
    while(filename[i]!='.'&&filename[i]!='\0'&&i>0)
    {

        i--;
    }
   // printf("%c\n",filename[i] );
    if(filename[i]=='\0'||filename[i+1]=='\0'||filename[i+2]=='\0')
    {return;} 
    char fn[200];
    strcpy(fn,filename);
    if(filename[i+1]=='o'&&filename[i+2]=='b'&&filename[i+3]=='j') 
    {
        fn[i+1]='o';fn[i+2]='f';fn[i+3]='f';
        objtooff(filename);
        _ReadOff_(mesh,fn,3); 
    }
    else if(filename[i+1]=='o'&&filename[i+2]=='f'&&filename[i+3]=='f')
    {
       // printf("read off\n"); 
        _ReadOff_(mesh,filename,3);
    }
    else if(filename[i+1]=='c'&&filename[i+2]=='e'&&filename[i+3]=='l'&&filename[i+4]=='l')
    {
       // printf("here\n");
        _ReadCell_(mesh,filename);
    }
}

#ifdef __cplusplus
}
#endif
#undef quote 
#undef _ReadOff_   
#undef _ReadCell_  
#undef _WriteCell_ 
#undef _ReadArray_ 

#endif